<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <script
      src="https://cdn.bootcdn.net/ajax/libs/vue/3.2.40/vue.global.js"
      type="application/javascript"
    ></script>
    <title>Document</title>
    <style>
      .class1 {
        background: rgb(47, 190, 114);
      }
      .abc {
        font-size: 20px;
      }
      .text-danger {
        color: red;
      }
      .active {
        border: solid 2px;
      }
    </style>
  </head>
  <body>
    <div id="app">
      <button :id="dis" :class="{class1:dis}" class="abc">见或者不见</button>
      <hr />
      <button :id="dis" :class="classObj">见或者不见</button>
      <hr />
      <div :class="myClass">计算后的样式</div>
      <hr />
      <div :class="[activeClass,errorClass]">绑定数组的样式</div>
      <hr />
      <div :class="[isActive ? activeClass : errorClass]">三元表达式的样式</div>
      <hr />
      内联样式例子
      <div :style="{color:myColor,fontSize:fontSize+'px'}">绑定内联样式</div>
      <hr />
      <div :style="styleObj">绑定内联样式</div>
      <hr />
      <div :style="[baseStyle,overStyle]">绑定内联样式数组</div>
    </div>
    <script>
      const app = Vue.createApp({
        data() {
          return {
            msg: "hello world",
            dis: true,
            classObj: {
              class1: false,
              abc: true,
            },
            isActive: true,
            error: false,
            activeClass: "active",
            errorClass: "text-danger",
            myColor: "blue",
            fontSize: 30,
            styleObj: {
              color: "red",
              fontSize: "30px",
            },
            baseStyle: {
              color: "green",
              fontSize: "50px",
            },
            overStyle: {
              "font-weight": "bold",
            },
          };
        },
        computed: {
          myClass() {
            return {
              active: this.isActive && !this.error,
              "text-danger": this.error,
            };
          },
        },
      });
      app.mount("#app");
    </script>
  </body>
</html>
